import {downFilePostJSON ,downFilePostUrl} from "@/api/fileDownload";
import Vue from 'vue'
import {axios} from '@/utils/request'
import fileDownload from "js-file-download";

export function getPage(data) {
    return axios({
        url: "/vatoutinv/matchFlowSelect/getPage",
        method: 'post',
        data
    })
}
export function queryFlowByItem(data) {
    return axios({
        url: '/vatoutinv/matchFlowSelect/queryFlowByItem',
        method: 'post',
        data
    })
}




export function exportList(parameter,method) {
    return downFilePostJSON('/vatoutinv/matchFlowSelect/export', parameter,method).then((data) => {
        if (!data || data.data.size === 0) {
            Vue.prototype['$message'].warning('文件下载失败')
            return
        }

        var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
        var contentDisposition = decodeURI(data.headers['content-disposition'])
        var result = patt.exec(contentDisposition)


        try {
            var fileName = result[1]
            fileName = fileName.replace(/\"/g, '')
        } catch (error) {
            return Vue.prototype['$message'].warning('文件下载失败')
        }
        if(!fileName) return Vue.prototype['$message'].warning('文件下载失败')

        fileDownload(data.data,fileName)
    })
}